package com.dm.cloud.tkmybatis.config;

import com.dm.cloud.core.mode.ResultModel;
import org.springframework.core.annotation.Order;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
@Order(1)
public class DbExceptionErrorAdvice {
//    @PostConstruct
//    public void init(){
//        System.out.println("数据库异常拦截器启动");
//    }
    //唯一性校验
    @ExceptionHandler(DuplicateKeyException.class)
    public ResponseEntity<ResultModel> handleCustomException(DuplicateKeyException e) {
        return ResponseEntity.status(500)
                .body(ResultModel.err(500,"数据重复，保存失败"));
    }
}
